

#import "USACell.h"
#import "MovieModel.h"
#import "RatingView.h"
@implementation USACell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self initSubviews];
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)initSubviews
{
    _image = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:_image];
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _titleLabel.textColor = [UIColor orangeColor];
    _titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:_titleLabel];
    
    _yearLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _yearLabel.textColor = [UIColor grayColor];
    _yearLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_yearLabel];
    
    _rating = [[RatingView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:_rating];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _image.frame = CGRectMake(15, 10, 80, 81);
    NSString *imageURL = [_movieModel.images objectForKey:@"medium"];
    [_image setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"3"]];
    
    _titleLabel.frame = CGRectMake(_image.right+10, _image.top+10, 220, 30);
    _titleLabel.text = _movieModel.title;
    
    _yearLabel.frame = CGRectMake(_titleLabel.left, _titleLabel.bottom+5, _titleLabel.width/3, 25);
    _yearLabel.text = [NSString stringWithFormat:@"年份:%@",_movieModel.year];
    
    _rating.frame = CGRectMake(_yearLabel.right+10, _yearLabel.top+6, 0, 0);
    _rating.style = kSmallStyle;
    _rating.ratingData = [[_movieModel.rating objectForKey:@"average"] floatValue];
}

@end
